<?php

include(dirname(__FILE__).'/../../bootstrap/functional.php');

$browser = new sfTestFunctional(new sfBrowser());

$browser->
        
  info( '1 - URL actions and states' )->
  
  info( '1.1 - Index page' )->
  get('/user_id')->

  with('request')->begin()->
    isParameter('module', 'user_id')->
    isParameter('action', 'index')->
    isMethod('get')->
  end()->

  with('response')->begin()->
    isStatusCode(200)->
    checkElement('body', '!/This is a temporary page/')->
    checkElement('form')->
    isValid()->
  end()->
  
  
  info( '1.2 - Show page' )->
  
  get('/user_id/Cyberpower678')->

  with('request')->begin()->
    isParameter('module', 'user_id')->
    isParameter('action', 'show')->
    isParameter('lang', 'en')->
    isParameter('wiki', 'wikipedia')->
    isMethod('get')->
  end()->

  with('response')->begin()->
    isStatusCode(200)->
    checkElement('body', '!/This is a temporary page/')->
    checkElement('body', '/The user ID for (.*) on (.*) is (\d*)/')->
    isValid()->
  end()->
  
  
  info( '1.3 - UTF show' )->
  get('/user_id/Ø')->

  with('request')->begin()->
    isParameter('module', 'user_id')->
    isParameter('action', 'show')->
    isParameter('lang', 'en')->
    isParameter('wiki', 'wikipedia')->
    isParameter('name', 'Ø' )->
    isMethod('get')->
  end()->

  with('response')->begin()->
    isStatusCode(200)->
    checkElement('body', '/The user ID for Ø on (.*) is (\d*)/')->
    isValid()->
  end()->
  
  
  info( '1.4 - Different language' )->
  get('/user_id/Cyberpower678/fr')->

  with('request')->begin()->
    isParameter('module', 'user_id')->
    isParameter('action', 'show')->
    isParameter('lang', 'fr')->
    isParameter('wiki', 'wikipedia')->
    isMethod('get')->
  end()->

  with('response')->begin()->
    isStatusCode(200)->
    checkElement('body', '!/View Source/')->
    isValid()->
  end()->
  
  
  
  
  
  
  
  
  info( '2 - Form submission' )->
  
  
  info( '2.1 - Normal form' )->
  get('/user_id')->

  with('request')->begin()->
    isParameter('module', 'user_id')->
    isParameter('action', 'index')->
    isMethod('get')->
  end()->
  
  click('Get user ID', 
        array(
                'name' => 'Foo'
        )
  )->
  
  with('form')->begin()->
    hasErrors(false)->
  end()->
  
  with('response')->isRedirected()->
    followRedirect()->
  
  with('request')->begin()->
    isParameter('module', 'user_id')->
    isParameter('action', 'show')->
    isParameter('lang', 'en')->
    isParameter('wiki', 'wikipedia')->
    isMethod('get')->
    
  end()->
  
  
  
  info( '2.2 - Different language' )->
  get('/user_id')->

  with('request')->begin()->
    isParameter('module', 'user_id')->
    isParameter('action', 'index')->
    isMethod('get')->
  end()->
  
  click('Get user ID', 
        array(
                'name' => 'Foo',
                'lang' => 'fr',
                'wiki' => 'wikisource'
        )
  )->
  
  with('form')->begin()->
    hasErrors(false)->
  end()->
  
  with('response')->isRedirected()->
    followRedirect()->
  
  with('request')->begin()->
    isParameter('module', 'user_id')->
    isParameter('action', 'show')->
    isParameter('lang', 'fr')->
    isParameter('wiki', 'wikisource')->
    isMethod('get')->
    
  end()->
  
  
  
  info( '2.3 - UTF form' )->
  get('/user_id')->

  with('request')->begin()->
    isParameter('module', 'user_id')->
    isParameter('action', 'index')->
    isMethod('get')->
  end()->
  
  click('Get user ID', 
        array(
                'name' => 'Ø'
        )
  )->
  
  with('form')->begin()->
    hasErrors(false)->
  end()->
  
  with('response')->isRedirected()->
    followRedirect()->
  
  with('request')->begin()->
    isParameter('module', 'user_id')->
    isParameter('action', 'show')->
    isParameter('lang', 'en')->
    isParameter('wiki', 'wikipedia')->
    isParameter('name', 'Ø' )->
    isMethod('get')->
    
  end()
  //->with('response')->begin()->debug()
;
